<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css"/>
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="../../js/jquery.js"></script>

    <!--    <script type="text/javascript" src="../../js/jquery-3.3.1.js"></script>-->
    <script type="text/javascript" src="../../js/axios.js"></script>
    <script type="text/javascript" src="../../js/api.js"></script>
    <script type="text/javascript" src="../../layui/layui.js"></script>

</head>
<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>采购管理</li>
        <li>采购单审核</li>
        <li>基本内容</li>
    </ul>
</div>
<div class="rightinfo">
    <form id="conn" action="" method="post">
        <ul class="tools">
            <li> 采购单编号:
                <input name="purchaseId" type="text"/>
            </li>
            <li> 采购时间:
                <input name="purchaseTimeStart" id="time1"/>-<input id="time2" name="purchaseTimeEnd"/>
            </li>
            <li> 金额:
                <input name="totalMoneyStart" id="m1" type="text" class="stinput"/>-<input id="m2" name="totalMoneyEnd"
                                                                                           type="text"
                                                                                           class="stinput"/>
            </li><!--onclick="window.location.href='purchaseExamineList.html'"-->
            <li class="subBut">
                <img src="../../images/t06.png"/>查询
            </li>
        </ul>
    </form>

    <table class="tablelist">
        <thead>
        <tr>
            <th>序号</th>
            <th>采购单编号</th>
            <th>采购时间</th>
            <th>金额</th>
            <th>操作人</th>
            <th>审核状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tList">
        <!--  <tr>
            <td>1</td>
            <td>DJ201701270001</td>
            <td>2017-01-25 15:05:05</td>
            <td>￥9,876,582</td>
            <td>关羽</td>
            <td>审核中</td>
            <td>
              <a href="purchaseExamine.html" class="tablelink">审核</a>
            </td>
          </tr>
          <tr>
            <td>2</td>
            <td>DJ201701270002</td>
            <td>2017-01-25 15:05:05</td>
            <td>￥9,876,582</td>
            <td>关羽</td>
            <td>审核中</td>
            <td>
              <a href="purchaseExamine.html" class="tablelink">审核</a>
            </td>
          </tr>-->
        </tbody>
    </table>
    <div class="pagin" id="page">
        <!-- <div class="message">共<i class="blue" id="totalCount">1256</i>条记录，当前显示第&nbsp;<i class="blue" id="pageNum">2&nbsp;</i>页
         </div>
         <ul class="paginList">
             <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
             <li class="paginItem"><a href="javascript:;">1</a></li>
             <li class="paginItem current"><a href="javascript:;">2</a></li>
             <li class="paginItem"><a href="javascript:;">3</a></li>
             <li class="paginItem"><a href="javascript:;">4</a></li>
             <li class="paginItem"><a href="javascript:;">5</a></li>
             <li class="paginItem more"><a href="javascript:;">...</a></li>
             <li class="paginItem"><a href="javascript:;">10</a></li>
             <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
         </ul>-->
    </div>
    <!--  </form>-->
</div>
<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
    let pageSize = 8;
    let conn = ''
    let pageNum = getParameter("pageNum") == null ? 1 : getParameter("pageNum");
    let cn = decodeURI(getParameter("condition"));
    conn = JSON.parse(cn) == null ? '' : JSON.parse(cn);
    $(function () {
        if (conn != '') {
            $("[name='purchaseId']").val(conn[0].value)
            $("[name='purchaseTimeStart']").val(conn[1].value)
            $("[name='purchaseTimeEnd']").val(conn[2].value)
            $("[name='totalMoneyStart']").val(conn[3].value)
            $("[name='totalMoneyEnd']").val(conn[4].value)
        }
        loadPurchase(pageNum, pageSize, conn)
    })
    //采购时间控件
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#time1'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#time2'
            , type: 'datetime'
        });
    })
    //查询框验证事件
    // layui.use('layer', function () {
    //     let layer = layui.layer
    //
    //     function checkDateTime() {
    //         let flag = true;
    //         let timeStart = $("#t1").val();
    //         let timeEnd = $("#t2").val();
    //         console.log(timeStart)
    //         console.log(timeEnd)
    //         if (timeStart > timeEnd) {
    //             layer.msg('搜索日期范围不对', {icon: 5});
    //             $("#purchaseTimeStart").css({"border-color": "red"})
    //             $("#purchaseTimeEnd").css({"border-color": "red"})
    //             flag = false;
    //         } else {
    //             $("#purchaseTimeStart").css({"border-color": ""})
    //             $("#purchaseTimeEnd").css({"border-color": ""})
    //         }
    //         return flag;
    //     }
    //
    //     function checkMoney() {
    //         let flag = true;
    //         let timeStart = $("#m1").val();
    //         let timeEnd = $("#m2").val();
    //         console.log(timeStart)
    //         console.log(timeEnd)
    //         if (timeStart > timeEnd) {
    //             layer.msg('搜索金额范围不对', {icon: 5});
    //             $("#totalMoneyStart").css({"border-color": "red"})
    //             $("#totalMoneyEnd").css({"border-color": "red"})
    //             flag = false;
    //         } else {
    //             $("#totalMoneyStart").css({"border-color": ""})
    //             $("#totalMoneyEnd").css({"border-color": ""})
    //         }
    //         return flag;
    //     }
    //
    //     $('.subBut').click(function () {
    //         if (checkDateTime() && checkMoney()) {
    //             conn = $('#conn').serializeArray()
    //             loadPurchase(0, pageSize, conn)
    //         } else {
    //             layer.msg('请填完整', {icon: 5});
    //             return false;
    //         }
    //     })
    //
    //     $('#t1').blur(checkDateTime)
    //     $('#t2').blur(checkDateTime)
    //
    //     $('#m1').blur(checkMoney)
    //     $('#m2').blur(checkMoney)
    // })

    //查询点击事件
    $('.subBut').click(function () {

        conn = $('#conn').serializeArray()
        loadPurchase(pageNum, pageSize, conn)
    })


    //加载数据
    function loadPurchase(pageNum, pageSize, conn) {
        axiosJson(
            'get',//提交方法
            '/purchase/view',//提交地址
            conn,
            {pageNum: pageNum, pageSize: pageSize,checkStatus:2}
        ).then((res) => {
            writeData(res)
        })

    }

    //写数据
    function writeData(res) {
        let str = ''
        let audit = res.data.resultData.data  //pageModel里purchase的数据
        let page = res.data.resultData   //查看pageModel 的属性值
        for (let i = 0; i < audit.length; i++) {
            // let status = audit[i].checkStatus;
            // var arr = ['未审核', '审核中', '审核通过', '审核未通过'];
            // for (let i = 0; i < arr.length; i++) {
            //     if (status == (i + 1)) status = arr[i]
            // }
            str += ' <tr>\n' +
                '          <td>' + ((page.pageNum - 1) * page.pageSize + i + 1)
                + '</td>\n' +
                '          <td>' + audit[i].purchaseId + '</td>\n' +
                '          <td>' + audit[i].purchaseTime + '</td>\n' +
                '          <td>￥' + audit[i].totalMoney + '</td>\n' +
                '          <td>' + audit[i].creator.uName + '</td>\n' +
                '          <td> 审核中</td>\n' +
                '          <td>\n' +
                `            <a href='purchaseExamine.html?purchaseId=` + audit[i].purchaseId + `&condition=` + encodeURI(JSON.stringify(conn)) + `&pageNum=` + pageNum + `' class="tablelink">审核</a>\n` +
                '          </td>\n' +
                '        </tr>'
        }

        $('#tList').html(str)
        $('.tablelist tbody tr:odd').addClass('odd');

        //页码显示
        layui.use("laypage", function () {
            var laypage = layui.laypage;
            laypage.render({
                elem: "page",                       //页码所放的位置
                theme: '#eb5409',
                count: page.totalCount,             //总记录数
                limit: page.pageSize,               //每页的数据
                limits: [5, 8, 12],                 //每页可访问的数据量
                curr: page.pageNum,                 //当前页
                layout: ['prev', 'page', 'next', 'limit', 'count', 'skip'],
                jump: function (obj, first) {
                    pageNum = obj.curr
                    pageSize = obj.limit
                    if (!first) {
                        loadPurchase(pageNum, pageSize, conn);
                    }
                }
            })
        })
    }

</script>
</body>
</html>
